<template>
  <div class="lesson-plans">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <div class="header-left">
          <h1 class="page-title">教案管理</h1>
          <p class="page-description">管理和组织您的所有教学资料</p>
        </div>
        <el-button type="primary" size="large" @click="handleCreate" :icon="Plus" round>
          创建新教案
        </el-button>
      </div>
    </div>
      
    <div class="main-container">
      <!-- 搜索和筛选区域 -->
      <div class="search-filter-card">
        <div class="filter-header">
          <h3>筛选条件</h3>
          <el-button text @click="resetFilters">重置</el-button>
        </div>
        
        <el-row :gutter="16">
          <el-col :xs="24" :sm="12" :lg="8">
            <el-input
              v-model="searchForm.keyword"
              placeholder="请输入教案标题关键词..."
              :prefix-icon="Search"
              clearable
              size="large"
              @clear="handleSearch"
              @keyup.enter="handleSearch"
            />
          </el-col>
          
          <el-col :xs="12" :sm="6" :lg="4">
            <el-select
              v-model="searchForm.subject"
              placeholder="学科"
              clearable
              size="large"
              @change="handleFilter"
            >
              <template #prefix>
                <el-icon><Reading /></el-icon>
              </template>
              <el-option
                v-for="subject in subjectOptions"
                :key="subject._id"
                :label="subject.name"
                :value="subject.name"
              />
            </el-select>
          </el-col>
          
          <el-col :xs="12" :sm="6" :lg="4">
            <el-select
              v-model="searchForm.grade"
              placeholder="年级"
              clearable
              size="large"
              @change="handleFilter"
            >
              <template #prefix>
                <el-icon><School /></el-icon>
              </template>
              <el-option
                v-for="grade in gradeOptions"
                :key="grade._id"
                :label="grade.name"
                :value="grade.name"
              />
            </el-select>
          </el-col>
          
          <el-col :xs="12" :sm="6" :lg="4">
            <el-select
              v-model="searchForm.courseType"
              placeholder="课程类型"
              clearable
              size="large"
              @change="handleFilter"
            >
              <template #prefix>
                <el-icon><Collection /></el-icon>
              </template>
              <el-option
                v-for="courseType in courseTypeOptions"
                :key="courseType._id"
                :label="courseType.name"
                :value="courseType.name"
              />
            </el-select>
          </el-col>
          
          <el-col :xs="12" :sm="6" :lg="4">
            <el-select
              v-model="searchForm.status"
              placeholder="状态"
              clearable
              size="large"
              @change="handleFilter"
            >
              <template #prefix>
                <el-icon><CircleCheck /></el-icon>
              </template>
              <el-option label="草稿" value="draft">
                <el-space>
                  <el-icon><Edit /></el-icon>
                  <span>草稿</span>
                </el-space>
              </el-option>
              <el-option label="已发布" value="published">
                <el-space>
                  <el-icon><CircleCheck /></el-icon>
                  <span>已发布</span>
                </el-space>
              </el-option>
              <el-option label="已归档" value="archived">
                <el-space>
                  <el-icon><FolderChecked /></el-icon>
                  <span>已归档</span>
                </el-space>
              </el-option>
            </el-select>
          </el-col>
        </el-row>
      </div>
        
      <!-- 统计信息 -->
      <div class="stats-grid" v-if="categoryStats">
        <div class="stat-card">
          <div class="stat-icon">
            <el-icon :size="24"><Document /></el-icon>
          </div>
          <div class="stat-content">
            <el-statistic :value="categoryStats.summary.totalLessonPlans" />
            <div class="stat-label">教案总数</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon" style="background: #ecf5ff; color: #409eff;">
            <el-icon :size="24"><Reading /></el-icon>
          </div>
          <div class="stat-content">
            <el-statistic :value="categoryStats.summary.totalSubjects" />
            <div class="stat-label">学科数量</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon" style="background: #f0f9ff; color: #67c23a;">
            <el-icon :size="24"><School /></el-icon>
          </div>
          <div class="stat-content">
            <el-statistic :value="categoryStats.summary.totalGrades" />
            <div class="stat-label">年级数量</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon" style="background: #fef0f0; color: #f56c6c;">
            <el-icon :size="24"><PriceTag /></el-icon>
          </div>
          <div class="stat-content">
            <el-statistic :value="categoryStats.summary.totalTags" />
            <div class="stat-label">标签数量</div>
          </div>
        </div>
      </div>
        
      <!-- 教案列表 -->
      <div class="lesson-list">
        <div class="list-header">
          <h3>教案列表</h3>
          <div class="list-actions">
            <el-button-group>
              <el-button :type="viewMode === 'table' ? 'primary' : 'default'" @click="viewMode = 'table'">
                <el-icon><Grid /></el-icon>
              </el-button>
              <el-button :type="viewMode === 'card' ? 'primary' : 'default'" @click="viewMode = 'card'">
                <el-icon><Files /></el-icon>
              </el-button>
            </el-button-group>
          </div>
        </div>
        
        <!-- 表格视图 -->
        <div v-if="viewMode === 'table'">
          <!-- 空状态提示 -->
          <div v-if="lessonPlans.length === 0 && !loading" class="empty-state">
            <el-empty 
              :image-size="120"
              description="请输入搜索关键词或选择筛选条件来查找教案"
            >
              <template #image>
                <el-icon :size="120" color="#d3d4d6"><Search /></el-icon>
              </template>
              <el-button type="primary" @click="handleCreate">创建第一个教案</el-button>
            </el-empty>
          </div>
          
          <el-table
            v-else
            :data="lessonPlans"
            v-loading="loading"
            style="width: 100%"
            @row-click="handleRowClick"
            :row-class-name="getRowClassName"
          >
          <el-table-column type="selection" width="55" />
          
          <el-table-column prop="title" label="教案标题" min-width="300">
            <template #default="{ row }">
              <div class="lesson-title-cell">
                <div class="title-content">
                  <span class="title-text">{{ row.title }}</span>
                  <div class="title-tags">
                    <el-tag
                      v-if="row.status === 'draft'"
                      type="info"
                      size="small"
                      effect="plain"
                    >
                      <el-icon><Edit /></el-icon>
                      草稿
                    </el-tag>
                    <el-tag
                      v-else-if="row.status === 'archived'"
                      type="warning"
                      size="small"
                      effect="plain"
                    >
                      <el-icon><FolderChecked /></el-icon>
                      已归档
                    </el-tag>
                    <el-tag
                      v-else
                      type="success"
                      size="small"
                      effect="plain"
                    >
                      <el-icon><CircleCheck /></el-icon>
                      已发布
                    </el-tag>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column label="分类" width="260">
            <template #default="{ row }">
              <div class="category-tags">
                <el-tag size="small">{{ row.subject }}</el-tag>
                <el-tag size="small" type="success">{{ row.grade }}</el-tag>
                <el-tag size="small" type="info">{{ row.courseType }}</el-tag>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column label="作者" width="160">
            <template #default="{ row }">
              <div class="author-cell">
                <el-avatar :size="32" :src="getAuthorAvatarUrl(row.author?.avatar)">
                  {{ row.author?.name?.charAt(0) }}
                </el-avatar>
                <span>{{ row.author?.name || '-' }}</span>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column label="数据" width="200">
            <template #default="{ row }">
              <div class="stats-cell">
                <div class="stat">
                  <el-icon><View /></el-icon>
                  <span>{{ row.views || 0 }}</span>
                </div>
                <div class="stat">
                  <el-icon><Star /></el-icon>
                  <span>{{ row.likes || 0 }}</span>
                </div>
                <div class="stat">
                  <el-icon><Comment /></el-icon>
                  <span>{{ row.comments?.length || 0 }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column label="更新时间" width="180" sortable>
            <template #default="{ row }">
              <div class="time-cell">
                <div>{{ formatDate(row.updatedAt) }}</div>
                <div class="time-relative">{{ getRelativeTime(row.updatedAt) }}</div>
              </div>
            </template>
          </el-table-column>
          
          <el-table-column label="操作" width="180" fixed="right">
            <template #default="{ row }">
              <div class="action-buttons">
                <el-button
                  type="primary"
                  text
                  bg
                  size="small"
                  @click.stop="handleView(row)"
                >
                  查看
                </el-button>
                <el-dropdown @command="(cmd) => handleCommand(cmd, row)" @click.stop>
                  <el-button text bg size="small">
                    更多 <el-icon><ArrowDown /></el-icon>
                  </el-button>
                  <template #dropdown>
                    <el-dropdown-menu>
                      <el-dropdown-item command="edit">
                        <el-icon><Edit /></el-icon>
                        编辑
                      </el-dropdown-item>
                      <el-dropdown-item command="copy">
                        <el-icon><CopyDocument /></el-icon>
                        复制
                      </el-dropdown-item>
                      <el-dropdown-item command="delete" divided>
                        <el-icon><Delete /></el-icon>
                        删除
                      </el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
              </div>
            </template>
          </el-table-column>
          </el-table>
        </div>
        
        <!-- 卡片视图 -->
        <div v-else class="card-grid" v-loading="loading">
          <!-- 空状态提示 -->
          <div v-if="lessonPlans.length === 0 && !loading" class="empty-state">
            <el-empty 
              :image-size="120"
              description="请输入搜索关键词或选择筛选条件来查找教案"
            >
              <template #image>
                <el-icon :size="120" color="#d3d4d6"><Search /></el-icon>
              </template>
              <el-button type="primary" @click="handleCreate">创建第一个教案</el-button>
            </el-empty>
          </div>
          
          <div
            v-for="lesson in lessonPlans"
            :key="lesson._id"
            class="lesson-card"
            @click="handleView(lesson)"
          >
            <div class="card-header">
              <h4>{{ lesson.title }}</h4>
              <el-dropdown @command="(cmd) => handleCommand(cmd, lesson)" @click.stop>
                <el-button :icon="More" circle text />
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item command="view">查看详情</el-dropdown-item>
                    <el-dropdown-item command="edit">编辑教案</el-dropdown-item>
                    <el-dropdown-item command="delete" divided>删除教案</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
            
            <div class="card-body">
              <div class="card-tags">
                <el-tag size="small">{{ lesson.subject }}</el-tag>
                <el-tag size="small" type="success">{{ lesson.grade }}</el-tag>
                <el-tag size="small" type="info">{{ lesson.courseType }}</el-tag>
              </div>
              
              <div class="card-author">
                <el-avatar :size="24" :src="getAuthorAvatarUrl(lesson.author?.avatar)">
                  {{ lesson.author?.name?.charAt(0) }}
                </el-avatar>
                <span>{{ lesson.author?.name }}</span>
              </div>
            </div>
            
            <div class="card-footer">
              <div class="card-stats">
                <span><el-icon><View /></el-icon> {{ lesson.views || 0 }}</span>
                <span><el-icon><Star /></el-icon> {{ lesson.likes || 0 }}</span>
                <span><el-icon><Comment /></el-icon> {{ lesson.comments?.length || 0 }}</span>
              </div>
              <div class="card-time">{{ getRelativeTime(lesson.updatedAt) }}</div>
            </div>
          </div>
        </div>
      </div>
        
      <!-- 分页 -->
      <div class="pagination-area">
        <el-pagination
          v-model:current-page="pagination.current"
          v-model:page-size="pagination.limit"
          :total="pagination.total"
          :page-sizes="[10, 20, 50, 100]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Document,
  Reading,
  School,
  PriceTag,
  View,
  Star,
  Comment,
  Plus,
  Search,
  Grid,
  Files,
  More,
  ArrowDown,
  Edit,
  CopyDocument,
  Delete,
  CircleCheck,
  FolderChecked,
  Collection,
  Clock
} from '@element-plus/icons-vue'
import { useAuthStore } from '@/stores/auth'
import { lessonPlanApi, type LessonPlan } from '@/api/lessonPlan'
import { categoryApi, type Category, type CategoryStatsResponse } from '@/api/category'

const router = useRouter()
const authStore = useAuthStore()

// 数据状态
const loading = ref(false)
const lessonPlans = ref<LessonPlan[]>([])
const subjectOptions = ref<Category[]>([])
const gradeOptions = ref<Category[]>([])
const courseTypeOptions = ref<Category[]>([])
const categoryStats = ref<CategoryStatsResponse | null>(null)
const viewMode = ref<'table' | 'card'>('table')

// 搜索表单
const searchForm = reactive({
  keyword: '',
  subject: '',
  grade: '',
  courseType: '',
  status: ''
})

// 分页信息
const pagination = reactive({
  current: 1,
  limit: 20,
  total: 0,
  pages: 0
})

// 移除权限判断 - 所有人都可以看到编辑删除按钮
const canEdit = () => true
const canDelete = () => true

// 格式化日期
const formatDate = (dateString: string) => {
  const date = new Date(dateString)
  return date.toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit'
  })
}

// 获取相对时间
const getRelativeTime = (dateString: string) => {
  const date = new Date(dateString)
  const now = new Date()
  const diff = now.getTime() - date.getTime()
  const seconds = Math.floor(diff / 1000)
  const minutes = Math.floor(seconds / 60)
  const hours = Math.floor(minutes / 60)
  const days = Math.floor(hours / 24)
  
  if (days > 7) {
    return formatDate(dateString)
  } else if (days > 0) {
    return `${days}天前`
  } else if (hours > 0) {
    return `${hours}小时前`
  } else if (minutes > 0) {
    return `${minutes}分钟前`
  } else {
    return '刚刚'
  }
}

// 获取行类名
const getRowClassName = ({ row }: { row: LessonPlan }) => {
  if (row.status === 'draft') return 'draft-row'
  if (row.status === 'archived') return 'archived-row'
  return ''
}

// 获取作者头像URL
const getAuthorAvatarUrl = (avatar?: string) => {
  if (!avatar) return ''
  
  // 如果已经是完整URL，直接返回
  if (avatar.startsWith('http')) {
    return avatar
  }
  
  // 开发环境下使用代理，直接返回相对路径
  // 生产环境需要配置 VITE_API_BASE_URL
  return avatar
}

// 重置筛选条件
const resetFilters = () => {
  searchForm.keyword = ''
  searchForm.subject = ''
  searchForm.grade = ''
  searchForm.courseType = ''
  searchForm.status = ''
  handleFilter()
}

// 加载分类选项
const loadCategories = async () => {
  try {
    const { data } = await categoryApi.getAll()
    if (data && data.grouped) {
      subjectOptions.value = data.grouped.subject || []
      gradeOptions.value = data.grouped.grade || []
      courseTypeOptions.value = data.grouped.courseType || []
    }
  } catch (error: any) {
    console.error('加载分类失败:', error)
  }
}

// 加载分类统计
const loadCategoryStats = async () => {
  try {
    const { data } = await categoryApi.getCategoryStats()
    if (data) {
      categoryStats.value = data
    }
  } catch (error: any) {
    console.error('加载统计信息失败:', error)
  }
}

// 加载教案列表
const loadLessonPlans = async () => {
  loading.value = true
  try {
    const params: any = {
      page: pagination.current,
      limit: pagination.limit
    }
    
    // 只添加非空的筛选参数
    if (searchForm.subject) params.subject = searchForm.subject
    if (searchForm.grade) params.grade = searchForm.grade
    if (searchForm.courseType) params.courseType = searchForm.courseType
    if (searchForm.status) params.status = searchForm.status
    
    // 检查是否有关键词搜索
    const hasKeywordSearch = searchForm.keyword && searchForm.keyword.trim()
    
    // 检查是否有筛选条件
    const hasFilterConditions = searchForm.subject || 
                               searchForm.grade || 
                               searchForm.courseType || 
                               searchForm.status
    
    let response
    if (hasKeywordSearch) {
      // 如果有关键词搜索，使用搜索接口
      response = await lessonPlanApi.search({
        q: searchForm.keyword,
        author: authStore.user?._id, // 只搜索当前用户的教案
        ...params
      })
    } else {
      // 如果只有筛选条件或没有任何条件，使用我的教案列表接口
      response = await lessonPlanApi.getMyList(params)
    }
    
    const { data } = response
    lessonPlans.value = data.lessonPlans
    pagination.total = data.pagination.total
    pagination.pages = data.pagination.pages || Math.ceil(data.pagination.total / pagination.limit)
  } catch (error: any) {
    ElMessage.error(error.message || '加载教案列表失败')
  } finally {
    loading.value = false
  }
}

// 处理搜索
const handleSearch = () => {
  pagination.current = 1
  loadLessonPlans()
}

// 处理筛选
const handleFilter = () => {
  pagination.current = 1
  loadLessonPlans()
}

// 处理分页大小变化
const handleSizeChange = (val: number) => {
  pagination.limit = val
  pagination.current = 1
  loadLessonPlans()
}

// 处理页码变化
const handlePageChange = (val: number) => {
  pagination.current = val
  loadLessonPlans()
}

// 处理创建教案
const handleCreate = () => {
  router.push('/lesson-plans/create')
}

// 处理查看教案
const handleView = (lessonPlan: LessonPlan) => {
  router.push(`/lesson-plans/${lessonPlan._id}`)
}

// 处理编辑教案
const handleEdit = (lessonPlan: LessonPlan) => {
  router.push(`/lesson-plans/${lessonPlan._id}/edit`)
}

// 处理删除教案
const handleDelete = async (lessonPlan: LessonPlan) => {
  try {
    await ElMessageBox.confirm(
      `确定要删除教案《${lessonPlan.title}》吗？此操作不可恢复。`,
      '删除确认',
      {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    await lessonPlanApi.delete(lessonPlan._id)
    ElMessage.success('删除成功')
    loadLessonPlans()
  } catch (error: any) {
    if (error !== 'cancel') {
      ElMessage.error(error.message || '删除失败')
    }
  }
}

// 处理行点击
const handleRowClick = (row: LessonPlan) => {
  handleView(row)
}

// 处理命令
const handleCommand = async (command: string, lessonPlan: LessonPlan) => {
  switch (command) {
    case 'view':
      handleView(lessonPlan)
      break
    case 'edit':
      handleEdit(lessonPlan)
      break
    case 'copy':
      ElMessage.info('复制功能开发中...')
      break
    case 'delete':
      await handleDelete(lessonPlan)
      break
  }
}

// 页面加载时初始化
onMounted(() => {
  loadCategories()
  loadCategoryStats()
  
  // 检查URL参数，如果有搜索参数则设置搜索表单
  const queryParam = router.currentRoute.value.query.q
  if (queryParam && typeof queryParam === 'string') {
    searchForm.keyword = queryParam
  }
  
  loadLessonPlans()
})
</script>

<style scoped>
.lesson-plans {
  min-height: calc(100vh - 100px);
  background-color: #f0f2f5;
}

/* 页面头部 */
.page-header {
  background: white;
  padding: 32px 24px;
  border-bottom: 1px solid #e4e7ed;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  flex: 1;
}

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: #303133;
  margin-bottom: 8px;
}

.page-description {
  margin: 0;
  font-size: 14px;
  color: #606266;
}

/* 主内容区域 */
.main-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* 搜索筛选卡片 */
.search-filter-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.filter-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

:deep(.el-select) {
  width: 100%;
}

:deep(.el-select .el-input__prefix) {
  color: #909399;
}

/* 统计网格 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.stat-icon {
  width: 48px;
  height: 48px;
  background: #f0f9ff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #409eff;
  flex-shrink: 0;
}

.stat-content {
  flex: 1;
}

.stat-content :deep(.el-statistic__number) {
  font-size: 24px;
  font-weight: 700;
  color: #303133;
}

.stat-label {
  font-size: 14px;
  color: #606266;
  margin-top: 4px;
}

/* 教案列表 */
.lesson-list {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.list-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

/* 表格样式 */
:deep(.el-table) {
  font-size: 14px;
  border-radius: 8px;
  overflow: hidden;
}

:deep(.el-table thead) {
  background: #f5f7fa;
}

:deep(.el-table thead th) {
  background: #f5f7fa;
  color: #606266;
  font-weight: 600;
  border-bottom: none;
}

:deep(.el-table__row) {
  cursor: pointer;
  transition: all 0.3s;
}

:deep(.el-table__row:hover) {
  background-color: #f5f7fa;
}

:deep(.el-table__row.draft-row) {
  opacity: 0.7;
}

:deep(.el-table__row.archived-row) {
  background-color: #fef0f0;
}

.lesson-title-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-content {
  flex: 1;
  min-width: 0;
}

.title-text {
  font-weight: 500;
  color: #303133;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-tags {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.category-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.author-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-cell {
  display: flex;
  gap: 16px;
  color: #909399;
  font-size: 13px;
}

.stats-cell .stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.time-cell {
  color: #606266;
  font-size: 13px;
}

.time-relative {
  color: #909399;
  font-size: 12px;
  margin-top: 2px;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

/* 卡片视图 */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  min-height: 400px;
}

.lesson-card {
  background: white;
  border: 1px solid #e4e7ed;
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
}

.lesson-card:hover {
  border-color: #409eff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.card-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-body {
  flex: 1;
  margin-bottom: 16px;
}

.card-tags {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.card-author {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #606266;
  font-size: 14px;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid #e4e7ed;
}

.card-stats {
  display: flex;
  gap: 12px;
  color: #909399;
  font-size: 13px;
}

.card-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-time {
  color: #909399;
  font-size: 12px;
}

/* 空状态 */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  grid-column: 1 / -1; /* 占满整行 */
}

.empty-state :deep(.el-empty__description) {
  color: #909399;
  font-size: 14px;
  margin: 16px 0 24px;
}

/* 分页 */
.pagination-area {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

:deep(.el-pagination) {
  font-weight: 400;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    padding: 20px 16px;
  }
  
  .header-content {
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }
  
  .page-title {
    font-size: 24px;
  }
  
  .main-container {
    padding: 16px;
  }
  
  .search-filter-card,
  .lesson-list {
    padding: 16px;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .card-grid {
    grid-template-columns: 1fr;
  }
  
  :deep(.el-table__cell) {
    padding: 8px;
  }
}
</style>